import Util from '../framework/util';

export const commitDateOptions = ({
    commit
}, value) => commit('setDateOptions', value);

export const commitResources = ({
    commit
}, value) => commit('setResources', value);

export const commitMiniApps = ({
    commit
}, value) => commit('setMiniApps', value);

export const getDefaultOption = (context, key) => {
    let dos = context.state.dateOptions[key];
    let dot = key.indexOf(".");
    if (dot > -1) {
        dos = context.state.dateOptions[key.substring(0, dot)][key.substring(dot + 1)];
    }
    return dos;
};

export const getDefaultYear = (context, key) => {
    let dos = getDefaultOption(context, key);
    if (Util.isArray(dos.value)) {
        return dos.key;
    } else {
        return dos.value;
    }
};

export const getDefaultMonth = (context, key) => {
    let dos = getDefaultOption(context, key);
    if (Util.isArray(dos.value)) {
        return dos.value[0];
    } else {
        return dos.value;
    }
};
export const commitModules = ({
    commit
}, value) => commit('setModules', value);